package com.yc;

import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class Test2_client {
    public static void main(String[] args) throws  Exception {
        InetAddress[] ia2 = InetAddress.getAllByName("www.baidu.com");
        if (ia2!=null) {
            for (InetAddress ia:ia2) {
                Socket client = new Socket();
                System.out.println("联接成功"+client);//Socket[addr=www.baidu.com/153.3.238.110,port=80,localport=53749]
                //基于TCP的客户端套接字对象             //百度的Http协议端口80            本机发送端口(通常是随机的)  接收端的接口
                break;
            }
        }
        Socket client2 = new Socket("www.baidu.com", 80);
        System.out.println("联接成功"+client2);

        Socket client3=new Socket("45.113.192.102",80);
        System.out.println("联接成功"+client3);
    }
}
